#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 155;
const double INF = 0x3f3f3f3f;
double d[N][N], maxn[N];
char g[N][N];
int n;
PII p[N];
double get_dist(PII a, PII b)
{
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i].x >> p[i].y;
	}
	for (int i = 0; i < n; i++) {
		cin >> g[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j) {
				if (g[i][j] == '1') {
					d[i][j] = get_dist(p[i], p[j]);
				}
				else {
					d[i][j] = INF;
				}
			}
		}
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	double ans1 = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (d[i][j] < INF) {
				maxn[i] = max(maxn[i], d[i][j]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (d[i][j] < INF) {
				ans1 = max(ans1, d[i][j]);
			}
		}
	}
	double ans2 = INF;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (d[i][j] >= INF) {
				ans2 = min(ans2, maxn[i] + get_dist(p[i], p[j]) + maxn[j]);
			}
		}
	}
	printf("%.lf", min(ans1, ans2));
	return 0;
}